package com.hy.mydesktop.client.component.factory;

import java.util.Date;

import com.extjs.gxt.ui.client.widget.DatePicker;
import com.extjs.gxt.ui.client.widget.DatePicker.DatePickerMessages;
import com.hy.mydesktop.client.component.meta.DatePickerModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;

/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-8-30；时间：上午09:19:29</li>
 * <li>类型名称：DatePickerFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class DatePickerFactory {

	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建DatePicker控件</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-30；时间：下午上午09:20:28</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaModel
	 * @return
	 */
	public static DatePicker createDatePicker(GxtComponentMetaNodeModel gxtComponentMetaModel){
		return configureDatePicker(gxtComponentMetaModel);
	}
	
	/**
	 * 
	 * 
	 * <ul>
	 * <li>方法含义：配置DatePicker控件的属性</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-30；时间：下午上午09:21:48</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static DatePicker configureDatePicker(GxtComponentMetaNodeModel gxtComponentMetaNodeModel){
		
		DatePicker picker=createDefaultDatePicker();
		picker = AbstractComponetFactory.configureAbstractComponet(picker, gxtComponentMetaNodeModel);

		
		if(gxtComponentMetaNodeModel.get(DatePickerModelEnum.MAXDATE.name().toLowerCase())!=null){
			//设置最大的允许日期
			picker.setMaxDate((Date)gxtComponentMetaNodeModel.get(DatePickerModelEnum.MAXDATE.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(DatePickerModelEnum.MINDATE.name().toLowerCase())!=null){
			//设置最小的允许日期
			picker.setMaxDate((Date)gxtComponentMetaNodeModel.get(DatePickerModelEnum.MINDATE.name().toLowerCase()));
			
		}
		if(gxtComponentMetaNodeModel.get(DatePickerModelEnum.MESSAGES.name().toLowerCase())!=null){
			//设置日期信息
			picker.setMessages((DatePickerMessages)gxtComponentMetaNodeModel.get(DatePickerModelEnum.MESSAGES.name().toLowerCase()));
		
		}
		if(gxtComponentMetaNodeModel.get(DatePickerModelEnum.STARTDAY.name().toLowerCase())!=null){
			//设置开始日期
			picker.setStartDay((Integer)gxtComponentMetaNodeModel.get(DatePickerModelEnum.STARTDAY.name().toLowerCase()));
			
		}
		if(gxtComponentMetaNodeModel.get(DatePickerModelEnum.VALUE.name().toLowerCase())!=null){
			//设置日期框的值
			picker.setValue((Date)gxtComponentMetaNodeModel.get(DatePickerModelEnum.VALUE.name().toLowerCase()));
			
		}
		
		return picker;
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建默认的DatePicker控件</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-30；时间：下午上午09:22:39</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	private static DatePicker createDefaultDatePicker(){
		DatePicker picker=new DatePicker();
		
		return picker;
	}
}
